﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace de.rwth.rz.campus.Mailer
{
    /// <remarks>
    /// 
    /// Copyright 2010 RWTH Aachen, CAMPUS Labs
    /// 
    /// Licensed under the Apache License, Version 2.0 (the "License");
    /// you may not use this file except in compliance with the License.
    /// You may obtain a copy of the License at
    ///
    /// http://www.apache.org/licenses/LICENSE-2.0
    ///
    /// Unless required by applicable law or agreed to in writing, software
    /// distributed under the License is distributed on an "AS IS" BASIS,
    /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    /// See the License for the specific language governing permissions and
    /// limitations under the License.
    /// 
    /// </remarks>


    [CLSCompliant(false)]
    public class GroupMailerSettings : LayoutsPageBase
    {
        protected InputFormRadioButton InputFormRadioButton1;
        protected InputFormRadioButton InputFormRadioButton2;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!Page.IsPostBack)
            {
                SPProperties settings = new SPProperties(SPControl.GetContextWeb(Context));
                Guid guid = new Guid(Request.QueryString["List"]);
                if (string.IsNullOrEmpty(settings["_" + guid + "sHOW"]) || settings["_" + guid + "sHOW"] == bool.FalseString)
                { InputFormRadioButton1.Checked = false; InputFormRadioButton2.Checked = true; }
                else
                { InputFormRadioButton2.Checked = false; InputFormRadioButton1.Checked = true; }
            }
        }

        public override string PageToRedirectOnCancel
        {
            get
            {
                return SPUrlUtility.CombineUrl(SPControl.GetContextWeb(Context).Url, "/_layouts/listedit.aspx?List=" + Request.QueryString["List"]);
            }
        }

        protected Button SubmitButton;
        public void SubmitButton_Click(object sender, System.EventArgs e)
        {
            SPProperties settings = new SPProperties(SPControl.GetContextWeb(Context));
            Guid guid = new Guid(Request.QueryString["List"]);

            if (InputFormRadioButton1.Checked)
                settings.SetValue("_" + guid + "sHOW", bool.TrueString);
            else
                settings.SetValue("_" + guid + "sHOW", bool.FalseString);

            Response.Redirect(SPUrlUtility.CombineUrl(SPControl.GetContextWeb(Context).Url, "/_layouts/listedit.aspx?List=" + Request.QueryString["List"]));
        }


    }
}
